import { consignee } from "../../api";
const MUTATION_TYPES = {
  CONSIGNEE_LIST: "CONSIGNEE_LIST",
  CONSIGNEE_SIZE: "CONSIGNEE_SIZE"
};

const state = {
  consigneeList: [],
  totalConsigneeSize: 0
};
const getters = {};

const mutations = {
  [MUTATION_TYPES.CONSIGNEE_LIST](state, consigneeList) {
    state.consigneeList = consigneeList;
  },
  [MUTATION_TYPES.CONSIGNEE_SIZE](state, totalConsigneeSize) {
    state.totalConsigneeSize = totalConsigneeSize;
  }
};

const actions = {
  async search({ commit }, filter = {}) {
    let response = await consignee.search(filter);
    if (response?.code === 0) {
      commit(MUTATION_TYPES.CONSIGNEE_LIST, response.data?.records);
      commit(MUTATION_TYPES.CONSIGNEE_SIZE, response.data?.total);
    }
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
